Assignemnt #102 and 102nd program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 102nd Program
///File name: Hund2prog.java
///Date Finished:3/29/2016
import java.util.Scanner;
public class Hund2prog
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner( System.in );
int choice, keychain = 0, keyPrice = 10, add, subtract, keychainsInOrder = 0;
System.out.println( "Ye old Keychain shoppe" );
System.out.println();
do
{
System.out.println( "1. Add keychains to order\n2. Remove Keychains from Order\n3. View current Order\n4. checkout" );
System.out.print( "Please enter your choice: " );
choice = keyboard. nextInt();
System.out.println();
if(choice == 1)
{
keychainsInOrder = addKeychains(keychainsInOrder);
System.out.println( "You now have " + keychainsInOrder + " keychains." );
}
else if(choice == 2)
{
keychainsInOrder = removeKeychains(keychainsInOrder);
System.out.println( "You now have " + keychainsInOrder + " keychains." );
}
else if(choice == 3)
{
String message = viewOrder(keychainsInOrder, keyPrice);
System.out.println( message );
}
else
{
String check = checkout(keychainsInOrder, keyPrice);
System.out.println( check );
}
}while (choice != 4);
}
public static int addKeychains(int keychain)
{
Scanner keyboard = new Scanner( System.in );
String x = "ADD KEYCHAINS";
int add;
System.out.print( "You have " + keychain + " keychains. How many to add? " );
add = keyboard.nextInt();
keychain = keychain + add;
return keychain;
}
public static int removeKeychains(int keychain)
{
Scanner keyboard = new Scanner( System.in );
String x = "REMOVE KEYCHAINS";
System.out.print( "You have " + keychain + " keychains. How many to remove? " );
int subtract = keyboard.nextInt();
keychain= keychain - subtract;
return keychain;
}
public static String viewOrder(int keychain, int keyPrice)
{
String x = "VIEW ORDER" , message;
message = "You have " + keychain + " keychain.\n Keychains cost $10 each. \nTotal cost is " + ( keyPrice * keychain );
return message;
}
public static String checkout(int keychain, int keyPrice)
{
Scanner keyboard = new Scanner( System.in );
String x = "CHECKOUT" , check, name;
System.out.print( "What is your name? " );
name = keyboard.next();
check = "You have " + keychain + " keychain.\n Keychains cost $10 each. \nTotal cost is " + viewOrder(keychain, keyPrice) + "\n Thanks for your order, " + name + "!";
return check;
}
}
Picture of the output